package cn.java81;

import cn.java81.myschool.dao.StudentDao;
import cn.java81.myschool.entity.Student;
import cn.java81.myschool.util.MyBatisUtil2;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.apache.ibatis.session.SqlSession;
import org.junit.Assert;
import org.junit.Test;

import java.util.List;

/**
 * @author oldliu
 * @since 1.0
 */
public class PagingStudent {

    @Test
    public void page(){
        SqlSession s= MyBatisUtil2.get();
        StudentDao mapper = s.getMapper(StudentDao.class);
        Page<Student> page = PageHelper.startPage(3, 5);

        List<Student> list = mapper.paging( "王", "4", null, null, null,null);
        //list.forEach(System.out::println);
        Assert.assertEquals(list.size(),page.getResult().size());
        page.getResult().forEach(System.out::println);
        Assert.assertTrue(list.size()<=5);
        System.out.println("总数是："+page.getTotal());
        System.out.println("总页数是："+page.getPages());

        MyBatisUtil2.close(s);
    }
}
